local skel = fk.CreateSkill{
  name = "tea__xuanfeng",
  tags = { Skill.Limited },
  attached_skill_name = "tea__xuanfeng_active&",
}
Fk:loadTranslationTable{
  ["tea__xuanfeng"] = "悬锋",
  [":tea__xuanfeng"] = "限定技，出牌阶段，你可以将一张牌当【闪电】使用。当此牌位于你/其他角色的判定区时，其他角色/你可以令此牌进行判定并视为使用一张【杀】。",
  ["@@tea__xuanfeng-inarea"] = "悬锋",
  ["#tea__xuanfeng-invoke"] = "悬锋：你可以将一张牌当【闪电】使用。",
}
---@type ViewAsSkillSpec
local xuanfeng = {
  mute = true,
  pattern = "lightning",
  prompt = "#tea__xuanfeng-invoke",
  card_filter = function (self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return end
    local c = Fk:cloneCard("lightning")
    c.skillName = skel.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function (self, player, use)
    local room = player.room
    room:notifySkillInvoked(player, skel.name, "big")
    local c = Fk:getCardById(use.card.subcards[1])
    room:setCardMark(c, "@@tea__xuanfeng-inarea", { Card.PlayerJudge, Card.Processing })
    room:setPlayerMark(player, "tea__xuanfeng_used", 1)
    for _, p in ipairs(room.alive_players) do
      room:handleAddLoseSkills(p, skel.attached_skill_name, nil, false, true)
    end
  end,
  enabled_at_response = Util.FalseFunc,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end
}
---@type TrigSkelSpec<PropertyChangeFunc>
local xuanfeng_re = {
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return true
    else
      return target == player
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if table.find(room.alive_players, function (p)
      return p:hasSkill(skel.name, true) and p:getMark("tea__xuanfeng_used") > 0
    end) and table.find(room:getAlivePlayers(), function (p)
      ---@diagnostic disable-next-line: return-type-mismatch
      return table.find(p:getCardIds("j"), function (id)
        return #Fk:getCardById(id):getTableMark("@@tea__xuanfeng-inarea") > 0
      end)
    end) then
      room:handleAddLoseSkills(player, skel.attached_skill_name, nil, false, true)
    else
      room:handleAddLoseSkills(player, "-" .. skel.attached_skill_name, nil, false, true)
    end
  end,
}
skel:addEffect("viewas", xuanfeng)
skel:addEffect(fk.AfterPropertyChange, xuanfeng_re)
return skel